<?php


abstract class BaseMailTask extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $user_id;


	
	protected $status_id = 1;


	
	protected $priority;


	
	protected $recipient_id;


	
	protected $subject;


	
	protected $mailto;


	
	protected $title;


	
	protected $body;


	
	protected $sender;


	
	protected $mailfrom;


	
	protected $updated_at;


	
	protected $created_at;


	
	protected $start_at;


	
	protected $sent_at;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getStatusId()
	{

		return $this->status_id;
	}

	
	public function getPriority()
	{

		return $this->priority;
	}

	
	public function getRecipientId()
	{

		return $this->recipient_id;
	}

	
	public function getSubject()
	{

		return $this->subject;
	}

	
	public function getMailto()
	{

		return $this->mailto;
	}

	
	public function getTitle()
	{

		return $this->title;
	}

	
	public function getBody()
	{

		return $this->body;
	}

	
	public function getSender()
	{

		return $this->sender;
	}

	
	public function getMailfrom()
	{

		return $this->mailfrom;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getStartAt($format = 'Y-m-d H:i:s')
	{

		if ($this->start_at === null || $this->start_at === '') {
			return null;
		} elseif (!is_int($this->start_at)) {
						$ts = strtotime($this->start_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [start_at] as date/time value: " . var_export($this->start_at, true));
			}
		} else {
			$ts = $this->start_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getSentAt($format = 'Y-m-d H:i:s')
	{

		if ($this->sent_at === null || $this->sent_at === '') {
			return null;
		} elseif (!is_int($this->sent_at)) {
						$ts = strtotime($this->sent_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [sent_at] as date/time value: " . var_export($this->sent_at, true));
			}
		} else {
			$ts = $this->sent_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = MailTaskPeer::ID;
		}

	} 
	
	public function setUserId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = MailTaskPeer::USER_ID;
		}

	} 
	
	public function setStatusId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->status_id !== $v || $v === 1) {
			$this->status_id = $v;
			$this->modifiedColumns[] = MailTaskPeer::STATUS_ID;
		}

	} 
	
	public function setPriority($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->priority !== $v) {
			$this->priority = $v;
			$this->modifiedColumns[] = MailTaskPeer::PRIORITY;
		}

	} 
	
	public function setRecipientId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->recipient_id !== $v) {
			$this->recipient_id = $v;
			$this->modifiedColumns[] = MailTaskPeer::RECIPIENT_ID;
		}

	} 
	
	public function setSubject($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->subject !== $v) {
			$this->subject = $v;
			$this->modifiedColumns[] = MailTaskPeer::SUBJECT;
		}

	} 
	
	public function setMailto($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->mailto !== $v) {
			$this->mailto = $v;
			$this->modifiedColumns[] = MailTaskPeer::MAILTO;
		}

	} 
	
	public function setTitle($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->title !== $v) {
			$this->title = $v;
			$this->modifiedColumns[] = MailTaskPeer::TITLE;
		}

	} 
	
	public function setBody($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->body !== $v) {
			$this->body = $v;
			$this->modifiedColumns[] = MailTaskPeer::BODY;
		}

	} 
	
	public function setSender($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->sender !== $v) {
			$this->sender = $v;
			$this->modifiedColumns[] = MailTaskPeer::SENDER;
		}

	} 
	
	public function setMailfrom($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->mailfrom !== $v) {
			$this->mailfrom = $v;
			$this->modifiedColumns[] = MailTaskPeer::MAILFROM;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = MailTaskPeer::UPDATED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = MailTaskPeer::CREATED_AT;
		}

	} 
	
	public function setStartAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [start_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->start_at !== $ts) {
			$this->start_at = $ts;
			$this->modifiedColumns[] = MailTaskPeer::START_AT;
		}

	} 
	
	public function setSentAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [sent_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->sent_at !== $ts) {
			$this->sent_at = $ts;
			$this->modifiedColumns[] = MailTaskPeer::SENT_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->user_id = $rs->getInt($startcol + 1);

			$this->status_id = $rs->getInt($startcol + 2);

			$this->priority = $rs->getInt($startcol + 3);

			$this->recipient_id = $rs->getInt($startcol + 4);

			$this->subject = $rs->getString($startcol + 5);

			$this->mailto = $rs->getString($startcol + 6);

			$this->title = $rs->getString($startcol + 7);

			$this->body = $rs->getString($startcol + 8);

			$this->sender = $rs->getString($startcol + 9);

			$this->mailfrom = $rs->getString($startcol + 10);

			$this->updated_at = $rs->getTimestamp($startcol + 11, null);

			$this->created_at = $rs->getTimestamp($startcol + 12, null);

			$this->start_at = $rs->getTimestamp($startcol + 13, null);

			$this->sent_at = $rs->getTimestamp($startcol + 14, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 15; 
		} catch (Exception $e) {
			throw new PropelException("Error populating MailTask object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(MailTaskPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			MailTaskPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(MailTaskPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

    if ($this->isNew() && !$this->isColumnModified(MailTaskPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(MailTaskPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = MailTaskPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += MailTaskPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = MailTaskPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = MailTaskPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUserId();
				break;
			case 2:
				return $this->getStatusId();
				break;
			case 3:
				return $this->getPriority();
				break;
			case 4:
				return $this->getRecipientId();
				break;
			case 5:
				return $this->getSubject();
				break;
			case 6:
				return $this->getMailto();
				break;
			case 7:
				return $this->getTitle();
				break;
			case 8:
				return $this->getBody();
				break;
			case 9:
				return $this->getSender();
				break;
			case 10:
				return $this->getMailfrom();
				break;
			case 11:
				return $this->getUpdatedAt();
				break;
			case 12:
				return $this->getCreatedAt();
				break;
			case 13:
				return $this->getStartAt();
				break;
			case 14:
				return $this->getSentAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = MailTaskPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUserId(),
			$keys[2] => $this->getStatusId(),
			$keys[3] => $this->getPriority(),
			$keys[4] => $this->getRecipientId(),
			$keys[5] => $this->getSubject(),
			$keys[6] => $this->getMailto(),
			$keys[7] => $this->getTitle(),
			$keys[8] => $this->getBody(),
			$keys[9] => $this->getSender(),
			$keys[10] => $this->getMailfrom(),
			$keys[11] => $this->getUpdatedAt(),
			$keys[12] => $this->getCreatedAt(),
			$keys[13] => $this->getStartAt(),
			$keys[14] => $this->getSentAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = MailTaskPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUserId($value);
				break;
			case 2:
				$this->setStatusId($value);
				break;
			case 3:
				$this->setPriority($value);
				break;
			case 4:
				$this->setRecipientId($value);
				break;
			case 5:
				$this->setSubject($value);
				break;
			case 6:
				$this->setMailto($value);
				break;
			case 7:
				$this->setTitle($value);
				break;
			case 8:
				$this->setBody($value);
				break;
			case 9:
				$this->setSender($value);
				break;
			case 10:
				$this->setMailfrom($value);
				break;
			case 11:
				$this->setUpdatedAt($value);
				break;
			case 12:
				$this->setCreatedAt($value);
				break;
			case 13:
				$this->setStartAt($value);
				break;
			case 14:
				$this->setSentAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = MailTaskPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setStatusId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setPriority($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setRecipientId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setSubject($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setMailto($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setTitle($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setBody($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setSender($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setMailfrom($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setUpdatedAt($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setStartAt($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setSentAt($arr[$keys[14]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(MailTaskPeer::DATABASE_NAME);

		if ($this->isColumnModified(MailTaskPeer::ID)) $criteria->add(MailTaskPeer::ID, $this->id);
		if ($this->isColumnModified(MailTaskPeer::USER_ID)) $criteria->add(MailTaskPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(MailTaskPeer::STATUS_ID)) $criteria->add(MailTaskPeer::STATUS_ID, $this->status_id);
		if ($this->isColumnModified(MailTaskPeer::PRIORITY)) $criteria->add(MailTaskPeer::PRIORITY, $this->priority);
		if ($this->isColumnModified(MailTaskPeer::RECIPIENT_ID)) $criteria->add(MailTaskPeer::RECIPIENT_ID, $this->recipient_id);
		if ($this->isColumnModified(MailTaskPeer::SUBJECT)) $criteria->add(MailTaskPeer::SUBJECT, $this->subject);
		if ($this->isColumnModified(MailTaskPeer::MAILTO)) $criteria->add(MailTaskPeer::MAILTO, $this->mailto);
		if ($this->isColumnModified(MailTaskPeer::TITLE)) $criteria->add(MailTaskPeer::TITLE, $this->title);
		if ($this->isColumnModified(MailTaskPeer::BODY)) $criteria->add(MailTaskPeer::BODY, $this->body);
		if ($this->isColumnModified(MailTaskPeer::SENDER)) $criteria->add(MailTaskPeer::SENDER, $this->sender);
		if ($this->isColumnModified(MailTaskPeer::MAILFROM)) $criteria->add(MailTaskPeer::MAILFROM, $this->mailfrom);
		if ($this->isColumnModified(MailTaskPeer::UPDATED_AT)) $criteria->add(MailTaskPeer::UPDATED_AT, $this->updated_at);
		if ($this->isColumnModified(MailTaskPeer::CREATED_AT)) $criteria->add(MailTaskPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(MailTaskPeer::START_AT)) $criteria->add(MailTaskPeer::START_AT, $this->start_at);
		if ($this->isColumnModified(MailTaskPeer::SENT_AT)) $criteria->add(MailTaskPeer::SENT_AT, $this->sent_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(MailTaskPeer::DATABASE_NAME);

		$criteria->add(MailTaskPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUserId($this->user_id);

		$copyObj->setStatusId($this->status_id);

		$copyObj->setPriority($this->priority);

		$copyObj->setRecipientId($this->recipient_id);

		$copyObj->setSubject($this->subject);

		$copyObj->setMailto($this->mailto);

		$copyObj->setTitle($this->title);

		$copyObj->setBody($this->body);

		$copyObj->setSender($this->sender);

		$copyObj->setMailfrom($this->mailfrom);

		$copyObj->setUpdatedAt($this->updated_at);

		$copyObj->setCreatedAt($this->created_at);

		$copyObj->setStartAt($this->start_at);

		$copyObj->setSentAt($this->sent_at);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new MailTaskPeer();
		}
		return self::$peer;
	}

} 